package de.grosjohann.android.feuerwehr.map;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

import de.grosjohann.android.feuerwehr.R;

public class MarkerOverlay
  extends Overlay {

  private GeoPoint geopoint;
  private Context context;

  public MarkerOverlay(Context ctx, GeoPoint point) {
    geopoint = point;
    context = ctx;
  }

  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    super.draw(canvas, mapView, shadow);

    Point screenPoint = new Point();
    mapView.getProjection().toPixels(geopoint, screenPoint);

    // die Hoehe darf nicht durch 2geteilt werden, da die Spitze des Markers unten ist.
    Bitmap markerImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.marker_red);
    canvas.drawBitmap(markerImage, screenPoint.x - markerImage.getWidth() / 2, screenPoint.y - markerImage.getHeight(),
        null);

    Bitmap shadowImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.marker_shadow);
    canvas.drawBitmap(shadowImage, screenPoint.x - markerImage.getWidth() / 2, screenPoint.y - markerImage.getHeight(),
        null);
  }
}
